<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>服务创建</title>
    <link rel="stylesheet" href="/box/layui/css/layui.css">
    <script src="/box/js/jquery-3.3.1.js"></script>
    <script src="/box/layui/layui.js"></script>
    <script src="/box/js/config.js"></script>
    <link rel="shortcut icon" href="/box/assets/ico/minus.png">
    <style>
        .box-pad {
            padding: 1%
        }
    </style>
</head>

<body>
    <div class="box-pad">
        <h1>服务创建</h1>
        <hr>
        <form class="layui-form" id="serviceForm" lay-filter="serviceForm">
            <input type="hidden" name="serviceId">
            <input type="hidden" name="founderId" id="founderId">
            <input type="hidden" name="state" value="1">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">客户</label>
                    <div class="layui-input-inline">
                        <input type="text" name="customerName" class="layui-input" placeholder="请输入客户名称">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">服务类型：</label>
                    <div class="layui-inline">
                        <select id="serviceType" name="serviceType">
                            <option value="-1">请选择</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">概要</label>
                <div class="layui-input-block">
                    <input type="text" name="outline" class="layui-input" placeholder="请输入概要">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务请求</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入请求" name="serviceRequest" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">创建人</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="founderName" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="creationTime" class="layui-input" id="creationTime" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center">
                <button class="layui-btn" onclick="sumb()">提交</button>
            </div>
        </form>
        <script>
            //  点击提交按钮
            function sumb() {
                var str = $("#serviceForm").serialize();
                $.post(`${new Config().base_url}/service/add`, str, das => {
                    layer.msg(das.msg);
                    setTimeout(function () {
                        $('#serviceForm')[0].reset();
                    } ,1000);
                });
            }
            //  layui渲染
            layui.use('form', function () {
                var form = layui.form;
                //  获取时间
                function getNow(s) {
                    return s < 10 ? '0' + s: s;
                }
                function dates() {
                    var now = new Date();
                    //格式化日，如果小于9，前面补0
                    var day = ("0" + now.getDate()).slice(-2);
                    //格式化月，如果小于9，前面补0
                    var month = ("0" + (now.getMonth() + 1)).slice(-2);
                    var h = now.getHours();
                    var minute = now.getMinutes();
                    var s = now.getSeconds();
                    //拼装完整日期格式
                    var today = now.getFullYear()+"-"+(month)+"-"+(day)+" "+getNow(h)+":"+getNow(minute)+":"+getNow(s);
                    return today;
                }
                //  给服务类型赋值
                $.get("http://localhost:8888/dictionary/serviceType", function (d) {
                    $.each(d.data,function () {
                        var options = $("<option></option>").appendTo("#serviceType");
                        options.text(this.entry).val(this.name);
                    });
                    form.render("select", "serviceForm");
                });
                //  获取创建人信息
                var login_user = JSON.parse(sessionStorage.getItem("login_user"));
                $("#founderId").val(login_user.user.userId);
                $("#founderName").val(login_user.user.userName);
                $("#creationTime").val(dates());
            });
        </script>
    </div>
</body>
</html>